package com.heima.controller;


import com.heima.Result;
import com.heima.domain.po.CheckupActivity;
import com.heima.domain.query.CheckupActivityQuery;
import com.heima.service.ICheckupActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 体检活动表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-07-28
 */
@Tag(name = "体检活动接口")
@RestController
@RequestMapping("checkup-activity")
public class CheckupActivityController {
    @Autowired
    private ICheckupActivityService checkupActivityService;

    @Operation(summary = "分页查询体检活动")
    @GetMapping("/page")
    public Result page(CheckupActivityQuery checkupActivityQuery) {
        return checkupActivityService.findByPage(checkupActivityQuery);
    }

    @Operation(summary = "新增体检活动")
    @PostMapping("/add")
    public Result add(@RequestBody CheckupActivity checkupActivity) {
        checkupActivity.setCreateTime(LocalDateTime.now());
        checkupActivity.setUpdateTime(LocalDateTime.now());
        checkupActivityService.save(checkupActivity);
        return Result.success();
    }

    @Operation(summary = "修改体检活动")
    @PutMapping("/update")
    public Result update(@RequestBody CheckupActivity checkupActivity) {
        checkupActivity.setUpdateTime(LocalDateTime.now());
        checkupActivityService.updateById(checkupActivity);
        return Result.success();
    }

    @Operation(summary = "根据id查询体检活动")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id) {
        CheckupActivity checkupActivity = checkupActivityService.getById(id);
        return Result.success(checkupActivity);
    }
}
